//
//  ChangePassWordViewController.m
//  tangshantongjiAPP
//
//  Created by yuntai on 2018/4/3.
//  Copyright © 2018年 yuntai. All rights reserved.
//

#import "ChangePassWordViewController.h"
#import "NSString+Verify.h"

@interface ChangePassWordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPwdTF;
@property (weak, nonatomic) IBOutlet UITextField *tNewPwdTF;
@property (weak, nonatomic) IBOutlet UITextField *tNew2PwdTF;

@end

@implementation ChangePassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"修改密码";

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)commintBtnAction:(UIButton *)sender {
    
    NSString *oldPwdStr = [self.oldPwdTF.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *newPwdStr1 = [self.tNewPwdTF.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *newPwdStr2 = [self.tNew2PwdTF.text stringByReplacingOccurrencesOfString:@" " withString:@""];

    if (oldPwdStr.length==0) {
        [HUDManager showWarningWithText:@"请输入旧密码"];
        return;
    }
    if (newPwdStr1.length==0) {
        [HUDManager showWarningWithText:@"请输入新密码"];
        return;
    }
    if (newPwdStr2.length==0) {
        [HUDManager showWarningWithText:@"请输入确认密码"];
        return;
    }
    
    if (![newPwdStr1 isEqualToString:newPwdStr2]) {
        [HUDManager showWarningWithText:@"两次输入的密码不一致"];
        self.tNew2PwdTF.text = nil;
        return;
    }
    if (![NSString judgePasswordLetterAndNumber:newPwdStr1]) {
        [HUDManager showWarningWithText:@"密码为6—12位数字和字母组合"];
        self.tNew2PwdTF.text = nil;
        self.tNewPwdTF.text = nil;
        return;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:oldPwdStr forKey:@"oldPassword"];
    [params setValue:newPwdStr1 forKey:@"newPassword"];
    [params setValue:kTokenID?:@"" forKey:@"token"];
    
    [NetWork PostNetWorkWithUrl:kUserChangePasswordAction with:params successBlock:^(NSDictionary *dic) {
        [[UserAccountManager shareUserAccountManager] logout];
    } FailureBlock:^(NSString *msg) {
        [HUDManager showWarningWithText:msg];

    } errorBlock:^(id error) {
        
    }];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
